//
//  ProductViewController.m
//  Consume100
//
//  Created by eliot on 16/3/28.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "ProductViewController.h"
#import "ProductTableViewCell.h"
#import "TransactionDetailsTableViewController.h"
#import "ImageTableViewCell.h"
#import "SpendAtStoreTableViewController.h"
#import "UIImageView+WebCache.h"
@interface ProductViewController ()<UITableViewDataSource, UITableViewDelegate>


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftTableViewW;


@property (weak, nonatomic) IBOutlet UITableView *leftTableView;

@property (weak, nonatomic) IBOutlet UITableView *rightTableView;

@property (nonatomic, strong) UITableView *productTableView;

/**左边数据源*/
@property (nonatomic, strong) NSArray *leftArr;
/**右边数据源*/
@property (nonatomic, strong) NSArray *rightArr;
/**左边按钮*/
@property (nonatomic, strong) UIButton *leftBtn;
/**右边按钮*/
@property (nonatomic, strong) UIButton *rightBtn;

/** 保存点击的是产品还是支付按钮*/
@property (nonatomic) BOOL isLeftBtn;


/** 背景视图*/
@property (nonatomic, strong) UIView *blackView;

@property (nonatomic, strong) UIView *bigView;


@property (weak, nonatomic) IBOutlet UIView *bottomView;


@property (weak, nonatomic) IBOutlet UILabel *totalLb;

@property (weak, nonatomic) IBOutlet UIButton *chosenBtn;


@property (weak, nonatomic) IBOutlet UILabel *marketLb;


@property (nonatomic, strong) UILabel *countLb;
@property (nonatomic) int startCount;

@property (nonatomic, strong) UIView *swapView;

@property (nonatomic) BOOL isSelectedRightBarBtn;
@property (nonatomic) BOOL isSelectedProductBtn;


/** 分类id*/
@property (nonatomic, strong) NSString *categoryId;



@end

@implementation ProductViewController

static long long myTotalPrice;

-(void)dealloc {
    myTotalPrice = 0;
}


-(UITableView *)productTableView {
    if (!_productTableView) {
        _productTableView = [[UITableView alloc] init];
        [self.view addSubview:_productTableView];
        _productTableView.delegate =self;
        _productTableView.dataSource = self;
        [_productTableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.view.mas_right);
            make.top.bottom.mas_equalTo(0);
            make.width.mas_equalTo(Width);
        }];
        [_productTableView registerNib:[UINib nibWithNibName:@"ImageTableViewCell" bundle:nil] forCellReuseIdentifier:@"imageCell"];
        _productTableView.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
        _productTableView.tableFooterView = [[UIView alloc] init];
    }
    return _productTableView;
}


-(UIView *)blackView {
    if (!_blackView) {
        //灰色背景
        self.blackView = [[UIView alloc] init];
        [self.view addSubview:_blackView];
   
        [self.blackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
        }];
        
        self.blackView .backgroundColor = [UIColor colorWithRed:205/255.0 green:205/255.0 blue:205/255.0 alpha:0.4];
    }
    return _blackView;
}

/**
 *  MARK：XIB创建
 *
 *  @return
 */

+(ProductViewController*)CreatProductViewController{
    
    UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    ProductViewController *productViewController=[story instantiateViewControllerWithIdentifier:@"ProductViewController"];
    
    return productViewController;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.leftTableViewW.constant = 110 / 320.0 * Width;
    self.isLeftBtn = YES;
    self.marketLb.layer.cornerRadius = 8;
    self.marketLb.layer.masksToBounds = YES;
    self.chosenBtn.layer.cornerRadius = 8;
    self.chosenBtn.layer.masksToBounds = YES;
    
    self.startCount = 0;
    
    [self.rightTableView registerNib:[UINib nibWithNibName:@"ProductTableViewCell" bundle:nil] forCellReuseIdentifier:@"ProductTableViewCell"];
    self.leftTableView.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
    /** 设置导航啦样式*/
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;
    [self setTitleView];
    self.leftTableView.tableFooterView = [[UIView alloc] init];
    self.rightTableView.tableFooterView = [[UIView alloc] init];
    
    self.marketLb.text = @"0";
    
    AFHTTPSessionManager *afManager = [AFHTTPSessionManager manager];
    afManager.responseSerializer = [AFHTTPResponseSerializer serializer];
    afManager.requestSerializer.timeoutInterval = 5;
    NSDictionary *dic = @{@"lbsShopId":self.shopId};
    NSString *baseUrl = [NSString stringWithFormat:@"%@getLbsCategory.jhtml", MyBaseURL];
    [afManager POST:baseUrl parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            self.leftArr = dic[@"businessCategoriesJson"];
            self.rightArr = dic[@"lbsShopProductJsons"];
            
            
            
            NSLog(@"%@", [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil]);
            if (self.leftArr.count > 0) {
                self.categoryId = self.leftArr[0][0][@"id"];
            }
            
            
            [self.leftTableView reloadData];
            [self.rightTableView reloadData];
        });
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUD];
            [MBProgressHUD showError:@"链接超时,请检查网络"];
        });
    }];
    
    
}

/**  点击扫一扫*/
- (void) clickSwap {
    self.isSelectedRightBarBtn = !self.isSelectedRightBarBtn;
    if (self.isSelectedRightBarBtn) {
        [self addRightAddView];
        self.blackView.hidden = NO;
    }else {
        [self.swapView removeFromSuperview];
        self.blackView.hidden = YES;
    }
}


- (void)addRightAddView {
    self.swapView = [[UIView alloc] init];
    self.swapView.layer.cornerRadius = 10;
    self.swapView.layer.masksToBounds = YES;
    self.swapView.backgroundColor = [UIColor whiteColor];
    [self.blackView addSubview:self.swapView];
    [self.swapView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(100, 96));
    }];
    UIImageView *shareIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iocn_alipay"]];
    [self.swapView addSubview:shareIV];
    shareIV.contentMode =  UIViewContentModeScaleAspectFit;
    [shareIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(23.0/2);
        make.left.mas_equalTo(23.0/2 - 2);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(25);
    }];
    UILabel *lb = [[UILabel alloc] init];
    [self.swapView addSubview:lb];
    lb.backgroundColor = [UIColor colorWithRed:205/255.0 green:205/255.0 blue:205/255.0 alpha:1];
    [lb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(47.5);
        make.height.mas_equalTo(1);
    }];
    
    UILabel *lb1 = [[UILabel alloc] init];
    lb1.text = @"扫一扫";
    [self.swapView addSubview:lb1];
    lb1.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
    [lb1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(shareIV.mas_right).mas_equalTo(4);
        make.top.right.mas_equalTo(0);
        make.height.mas_equalTo(47);
    }];
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.swapView addSubview:btn1];
    btn1.backgroundColor = [UIColor clearColor];
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(47);
    }];
    

    UIImageView *scanIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_wechat"]];
    [self.swapView addSubview:scanIV];
    [scanIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-23.0/2);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(25);
        make.left.mas_equalTo(23.0/2 - 2);
    }];
    scanIV.contentMode =  UIViewContentModeScaleAspectFit;
    
    
    UILabel *lb2 = [[UILabel alloc] init];
    lb2.text = @"扫一扫";
    [self.swapView addSubview:lb2];
    lb2.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
    [lb2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(scanIV.mas_right).mas_equalTo(4);
        make.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(47.5);
    }];
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.swapView addSubview:btn2];
    btn2.backgroundColor = [UIColor clearColor];
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(47.5);
    }];
    [btn1 addTarget:self action:@selector(shareBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [btn2 addTarget:self action:@selector(scanBtnClick) forControlEvents:UIControlEventTouchUpInside];
}

/** 支付宝扫一扫*/
- (void)shareBtnClick {

    
    
}
/** 微信扫一扫*/
- (void)scanBtnClick {
    
    
    
}


#pragma mark - bigView
- (void)setTitleViewWithImageWithDic:(NSDictionary *)dataDic andIndexPath:(NSIndexPath *)indexpath{
    self.bigView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, Width - 20, Width - 20 +44)];
    [self.blackView addSubview:self.bigView];
    self.bigView.backgroundColor = [UIColor whiteColor];
    UIImageView *iv = [[UIImageView alloc] init];
    [iv sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.188:8080%@", dataDic[@"productImg"]]]];
    [self.bigView addSubview:iv];
    [iv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(Width - 20, Width - 20));
    }];
    UILabel *titleLb = [[UILabel alloc] init];
    [self.bigView addSubview:titleLb];
    titleLb.text = dataDic[@"productName"];
    [titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(8);
        make.right.mas_equalTo(- Width / 2.0);
        make.top.mas_equalTo(iv.mas_bottom).mas_equalTo(8);
        make.height.mas_equalTo(20);
    }];
    UILabel *priceLb = [[UILabel alloc] init];
    [self.bigView addSubview:priceLb];
    priceLb.textAlignment  = NSTextAlignmentRight;
    priceLb.text = [NSString stringWithFormat:@"￥%ld", [dataDic[@"productPrice"] longValue]];
    priceLb.textColor = [UIColor redColor];
    [priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(- 30);
        make.left.mas_equalTo(Width / 2.0);
        make.top.mas_equalTo(iv.mas_bottom).mas_equalTo(8);
        make.height.mas_equalTo(20);
    }];

    self.bigView.transform = CGAffineTransformMakeScale(0.0, 0.0);
}

- (void)showBigView {
    self.blackView.hidden = NO;
    [UIView animateWithDuration:0.75 animations:^{
        
        self.bigView.transform = CGAffineTransformMakeScale(1.0, 1.0);
        
    }];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    [UIView animateWithDuration:0.75 animations:^{
        self.bigView.transform = CGAffineTransformMakeScale(0.0, 0.0);
        self.blackView.hidden = YES;
        [self.bigView removeFromSuperview];
    }];
}


#pragma mark - titleView

- (void)setTitleView {
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 134/414.0 *Width, 35)];//allocate titleView
    [titleView setBackgroundColor:[UIColor clearColor]];
    titleView.layer.borderWidth = 1;
    titleView.layer.borderColor = [[UIColor whiteColor] CGColor];
    titleView.layer.cornerRadius = 16;
    titleView.layer.masksToBounds = YES;
    self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftBtn.frame = CGRectMake(0, 0, titleView.frame.size.width / 2, 35);
    [self.leftBtn setTitle:@"产品" forState:UIControlStateNormal];
    [self.leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [titleView addSubview:self.leftBtn];
    self.rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(titleView.frame.size.width / 2, 0, titleView.frame.size.width / 2, 35)];
    [self.rightBtn addTarget:self action:@selector(clickPayBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.leftBtn addTarget:self action:@selector(clickProductBtn) forControlEvents:UIControlEventTouchUpInside];
    self.rightBtn.backgroundColor = [UIColor clearColor];
    [self.rightBtn setTitle:@"支付" forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.leftBtn.backgroundColor = [UIColor whiteColor];
    [titleView addSubview:self.rightBtn];
    //Set to titleView
    [self.navigationItem.titleView sizeToFit];
    self.navigationItem.titleView = titleView;
}

/** 点击顶部支付按钮*/
- (void)clickPayBtn {
    self.isLeftBtn = NO;
    [self.rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.rightBtn.backgroundColor = [UIColor whiteColor];
    [self.leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.leftBtn.backgroundColor = [UIColor clearColor];
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_scan"] style:UIBarButtonItemStylePlain target:self action:@selector(clickSwap)];
    self.navigationItem.rightBarButtonItem = rightBtn;
    [UIView animateWithDuration:0.25 animations:^{
        self.productTableView.transform = CGAffineTransformMakeTranslation(-Width, 0);
        self.leftTableView.alpha = 0;
        self.rightTableView.alpha = 0;
    }];
}
/** 点击顶部产品按钮*/
- (void)clickProductBtn {
    self.isLeftBtn = NO;
    [self.leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.leftBtn.backgroundColor = [UIColor whiteColor];
    [self.rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.rightBtn.backgroundColor = [UIColor clearColor];
    self.navigationItem.rightBarButtonItem = nil;
    [UIView animateWithDuration:0.55 animations:^{
        self.leftTableView.alpha = 1;
        self.rightTableView.alpha = 1;
        self.productTableView.transform = CGAffineTransformMakeTranslation(Width, 0);
    }];
}

/**  点击已选好*/
- (IBAction)clickChosenBtn:(id)sender {
    
    TransactionDetailsTableViewController *vc = [TransactionDetailsTableViewController CreatTransactionDetailsTableViewController];
    [self creatNav:vc];
    
    
}



#pragma mark - tableView (tableViewDelegate/tableViewDataSource)


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (tableView == self.productTableView) {
        return 3;
    }else {
        return 1;
    }

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (tableView == self.leftTableView) {
        return self.leftArr.count;
    }else if (tableView == self.productTableView){
        if (section == 0) {
            return 3;
        }else if (section == 1) {
            return 2;
        }else {
            return 1;
        }
    } else {
        return self.rightArr.count;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.leftTableView) {
        UITableViewCell *leftCell = [tableView dequeueReusableCellWithIdentifier:@"leftCell"];
        if (!leftCell) {
            leftCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"leftCell"];
            
            leftCell.textLabel.text = self.leftArr[indexPath.row][0][@"name"];
            leftCell.textLabel.textAlignment = NSTextAlignmentCenter;
            leftCell.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
        }
        return leftCell;
    }else if (tableView == self.productTableView){
        
        if (indexPath.section == 0) {
            switch (indexPath.row) {
                case 0:
                {
                    ImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"imageCell" forIndexPath:indexPath];
                    cell.ivW.constant = Width;
                    cell.ivH.constant = 196/400.0*Width;
                    cell.iconIV.image = [UIImage imageNamed:@"wem"];
                    return cell;
                }
                    break;
                case 1:
                {
                    UITableViewCell *phoneCell = [tableView dequeueReusableCellWithIdentifier:@"phoneCell"];
                    if (!phoneCell) {
                        phoneCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"phoneCell"];
                    }
                    phoneCell.textLabel.text = @"探鱼(天娱广场)";
                    phoneCell.detailTextLabel.text = @"美食，烤鱼";
                    phoneCell.textLabel.textColor = [UIColor colorWithRed:88/255.0 green:88/255.0 blue:88/255.0 alpha:1];
                    phoneCell.detailTextLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
                    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_phone-1"]];
                    iv.contentMode = UIViewContentModeScaleAspectFit;
                    phoneCell.accessoryView = iv;
                    UILabel *bgLb = [[UILabel alloc] init];
                    bgLb.backgroundColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
                    [phoneCell addSubview:bgLb];
                    bgLb.frame = CGRectMake(Width - 60, 10, 1, 40);
                    return phoneCell;
                }
                    break;
                default:
                {
                    
                    UITableViewCell *weizhiCell = [tableView dequeueReusableCellWithIdentifier:@"weizhiCell"];
                    if (!weizhiCell) {
                        weizhiCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"weizhiCell"];
                    }
                    UILabel *weizhiLb = [[UILabel alloc] init];
                    [weizhiCell addSubview:weizhiLb];
                    weizhiLb.text = @"广州市天河区天河路623号天娱广场5楼B区";
                    weizhiLb.frame = CGRectMake(15, 0, Width - 100, 44);
                    UILabel *bgLb = [[UILabel alloc] init];
                    bgLb.backgroundColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
                    [weizhiCell addSubview:bgLb];
                    bgLb.frame = CGRectMake(Width - 60, 5, 1, 30);
                    weizhiLb.textColor = [UIColor colorWithRed:88/255.0 green:88/255.0 blue:88/255.0 alpha:1];
                    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_adder"]];
                    iv.contentMode = UIViewContentModeScaleAspectFit;
                    weizhiCell.accessoryView = iv;
                    return weizhiCell;
                }
                    break;
            }
        }else if (indexPath.section == 1) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
            }
            if (indexPath.row == 1) {
                cell.textLabel.text = @"商家促销";
                UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                cell.textLabel.textColor = [UIColor colorWithRed:88/255.0 green:88/255.0 blue:88/255.0 alpha:1];
                cell.detailTextLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
                iv.frame = CGRectMake(0, 0, 12, 12);
                iv.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = iv;
            
            }else {
                cell.textLabel.text = @"图文详情";
                UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                iv.frame = CGRectMake(0, 0, 12, 12);
                cell.textLabel.textColor =[UIColor colorWithRed:88/255.0 green:88/255.0 blue:88/255.0 alpha:1];
                cell.detailTextLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
                iv.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = iv;
            }
            return cell;
        }else {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"lastCell"];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"lastCell"];
            }
            cell.backgroundColor = [UIColor whiteColor];
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [cell addSubview:btn];
            btn.backgroundColor = [UIColor colorWithRed:255/255.0 green:88/255.0 blue:88/255.0 alpha:1];
            [btn setTitle:@"面对面支付" forState:UIControlStateNormal];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(25);
                make.right.mas_equalTo(-25);
                make.top.mas_equalTo(5);
                make.height.mas_equalTo(35);
            }];
            btn.layer.cornerRadius = 8;
            btn.layer.masksToBounds = YES;
            [btn addTarget:self action:@selector(faceToFacePay) forControlEvents:UIControlEventTouchUpInside];
            UILabel *centerLb = [[UILabel alloc] init];
            centerLb.text = @"欢迎到店消费，赚取金币增值，APP上买单尊享更多优惠";
            centerLb.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
            [cell addSubview:centerLb];
            [centerLb mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(btn.mas_bottom).mas_equalTo(5);
                make.left.right.mas_equalTo(0);
                make.height.mas_equalTo(15);
            }];
            centerLb.font = [UIFont systemFontOfSize:12];
            centerLb.textAlignment = NSTextAlignmentCenter;
            return cell;
        }
    } else {
        
        ProductTableViewCell *rightCell = [tableView dequeueReusableCellWithIdentifier:@"ProductTableViewCell" forIndexPath:indexPath];
        rightCell.iconIV.layer.cornerRadius = 8;
        rightCell.iconIV.layer.masksToBounds = YES;
        NSDictionary *dic = self.rightArr[indexPath.row];
        rightCell.dataDic = dic;
        rightCell.checkProduct = ^(NSString *totalCount, NSString *totalPrice){
            self.marketLb.text = [NSString stringWithFormat:@"%d",[totalCount intValue] + [self.marketLb.text intValue]];
            
            long long price1 = [totalPrice longLongValue] * [totalCount integerValue];
            myTotalPrice = myTotalPrice + price1;
            self.totalLb.text = [NSString stringWithFormat:@"总价：￥%lld",myTotalPrice];
        };
        return rightCell;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.leftTableView) {
        return 44;
    }else if (tableView == self.productTableView) {
        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                return  196/400.0*Width;
            }else if (indexPath.row == 1) {
                return 60;
            }else {
                return 44;
            }
        }else if (indexPath.section == 1) {
            return 44;
        }else {
            return 70;
        }
    } else {
        return 118;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.leftTableView) {
        
        self.categoryId = self.leftArr[indexPath.row][0][@"id"];
        NSMutableArray *arr = [NSMutableArray array];
        for (int i = 0; i < indexPath.row; i++) {
            NSString *cateId = self.leftArr[i][0][@"id"];
            for (NSDictionary *dic in self.rightArr) {
                if ([dic[@"categoryId"] isEqualToString:cateId]) {
                    [arr addObject:dic];
                }
            }
        }
        NSIndexPath *index = [NSIndexPath indexPathForRow:arr.count inSection:0];
        [self.rightTableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES];
        
    }else if (tableView == self.productTableView) {
    
        
    } else {
        NSDictionary *dic = self.rightArr[indexPath.row];
        [self setTitleViewWithImageWithDic:dic andIndexPath:indexPath];
        [self showBigView];
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (tableView == self.productTableView) {
        if (section == 0) {
            return 0;
        }else {
            return 10;
        }
    }else {
        return 0;
    }
}


/** 面对面支付*/
- (void)faceToFacePay {
    SpendAtStoreTableViewController *vc = [SpendAtStoreTableViewController CreatSpendAtStoreTableViewController];
    [self creatNav:vc];
}


//创建模态导航控制器
-(void)creatNav:(UIViewController *)view{
    
    UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:view];
    nav.navigationBar.barTintColor = [UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1];
    view.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
    [self presentViewController:nav animated:YES completion:nil];
}

- (void)dismiss {
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
